#!/usr/bin/env bash

set -ve

export LFS='/mnt/lfs'

_USER=`whoami`
if [ "$_USER" != "lfs" ];
then
    echo 'WARNING: User lfs ONLY!!!' && exit;
fi

############################### Glibc ###############################

cd $LFS/sources/
rm -rf glibc-2.29/
tar -xvf glibc-2.29.tar.xz
cd glibc-2.29/

mkdir -pv build/
cd build/

../configure                             \
      --prefix=/tools                    \
      --host=$LFS_TGT                    \
      --build=$(../scripts/config.guess) \
      --enable-kernel=3.2                \
      --with-headers=/tools/include
make
make install

# 确认新工具链的基本功能（编译和链接）是否能正常运行
echo 'int main(){}' > dummy.c
$LFS_TGT-gcc dummy.c
readelf -l a.out | grep ': /tools'
# 64bit: [Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2]
# 32bit: [Requesting program interpreter: /tools/lib/ld-linux.so.2]
rm -v dummy.c a.out
